import os
import sys

from common.content_type import ContentType
from common.time_bdp import time_bdp
from core.result_base import ResultBase
from api.task import task
from common.logger import logger
from common.user_agent import useragent
import urllib3
urllib3.disable_warnings()

BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(BASE_PATH)



def task_status(access_token,task_id,_t=time_bdp.time_stamp_13(),_xsrf=None):
    """
    获取任务状态
    :param _t: 13位的时间戳
    :param task_id: 任务id
    :param _xsrf :
    :return: 自定义的关键字返回结果 result
    """
    result = ResultBase()
    payload = {
        "task_id": task_id,
        "_t": _t,
        "_xsrf":_xsrf
    }

    headers = {
        "Content-Type": ContentType.APPLICATION_JSON.value,
        "User-Agent": useragent.get_user_agent_one()
   }

    cookies = {
        "access_token":access_token
    }


    res = task.task_status(params=payload, headers=headers,cookies=cookies)
    result.success = False
    if res.json()["status"] == "0":
        result.success = True
    else:
        result.error = "接口返回码是 【 {} 】, 返回信息：{} ".format(res.json()["errstr"], res.json())
    result.payload = res.json()
    result.response = res
    logger.info("获取任务状态 ==>> 返回结果 ==>> {}".format(result.response.text))
    return result








